home *** CD-ROM | disk | FTP | other *** search
/ Packard Bell - Internet on a CD / internet on a cd.cdr / Internet / sites / Clementine_NASA / image.hqx / Image folder / Macros / More Macros < prev    next >
Encoding:
Text File  |  1991-08-05  |  8.0 KB  |  387 lines

  1. macro 'Make Mosaic';
  2. var
  3.   n:integer;
  4. begin
  5.   SaveState
  6.   n:=GetNumber('Cell Size(pixels square):',8);
  7.   Duplicate('Mosaic');
  8.   SetScaling('Nearest; Same Window');
  9.   ScaleSelection(1/n,1/n);
  10.   RestoreRoi;
  11.   ScaleSelection(n,n);
  12.   RestoreState;
  13. end;
  14.  
  15.  
  16. macro 'Draw Vertical Scale with Labels';
  17. var
  18.   left,top,width,height,i,x,y2,inc:integer;
  19.   y:real;
  20. begin
  21.   GetRoi(left,top,width,height);
  22.   if width=0 then begin
  23.     PutMessage('Make a selection first.');
  24.     exit;
  25.   end;
  26.   SetFont('Helvetica');
  27.   SetFontSize(10);
  28.   SetText('Plain; Left; no background');
  29.   SetLineWidth(1);
  30.   Setforeground(255);
  31.   DrawScale;
  32.   x:=left;
  33.   y:=top;
  34.   inc:=height/10;
  35.   for i:=1 to 11 do begin
  36.     MoveTo(x+width+10,round(y)+2);
  37.     y2:=round(y);
  38.     if i=11 then y2:=y2-1;
  39.     write(cvalue(GetPixel(x,y2)):1:2);
  40.     y:=y+inc;
  41.   end;
  42. end;
  43.  
  44.  
  45. macro 'Speckle Paint [S]';
  46. var
  47.   x,y,ranx,rany,MaxSpeckSize,size,Spread:integer;
  48. begin
  49.   {SaveState;}
  50.   Spread:=50;
  51.   MaxSpeckSize:=5;
  52.   KillRoi;
  53.   repeat
  54.     GetMouse(x,y);
  55.     if button then begin
  56.       ranx:=x+Spread*(Random-0.5);
  57.       rany:=y+Spread*(Random-0.5);
  58.       size:=(MaxSpeckSize-2)*random+2;
  59.       MakeOvalRoi(ranx-size,rany-size,size*2,size*2);
  60.       SetForeground(Random*254+1)
  61.       fill;
  62.     end;
  63.   until (x<0) or (y<0);
  64.   KillRoi;
  65.   {RestoreState;}
  66. end;
  67.  
  68.  
  69. macro 'Draw Histogram';
  70. var
  71.   max,scale:real;
  72.   i,margin,width,height:integer;
  73. begin
  74.   SaveState;
  75.   Margin:=10;
  76.   width:=256;
  77.   height:=0.6*256;
  78.   Measure;
  79.   SetForegroundColor(255);
  80.   SetBackgroundColor(0);
  81.   SetLineWidth(1);
  82.   SetNewSize(width+2*margin,height+2*margin);
  83.   MakeNewWindow('Histogram');
  84.   MakeRoi(margin,margin-1,width,height+1);
  85.   DrawBoundary;
  86.   max:=0;
  87.   for i:=1 to 254 do
  88.   if histogram[i]> max then max:=histogram[i];
  89.   scale:=height/max;
  90.   for i:=1 to 254 do begin
  91.     MakeRoi(margin+i,margin,1,histogram[i]*scale);
  92.     SetForegroundColor(i);
  93.     fill;
  94.  end;
  95.   SelectAll;
  96.   FlipVertical;
  97.   KillRoi;
  98.   RestoreState;
  99. end;
  100.  
  101.  
  102. macro 'Subtract Background';
  103. var
  104.   i,Corrected:integer;
  105. begin
  106.   SelectAll;
  107.   Duplicate('Background Corrected');
  108.   Corrected:=PicNumber;
  109.   Duplicate('Background'); 
  110.   ScaleSelection(.25,.25);
  111.   RestoreRoi;
  112.   for i:=1 to 10 do begin
  113.     SetOption; Smooth;
  114.   end;
  115.   ScaleSelection(4,4);
  116.   SelectAll;
  117.   Copy;
  118.   SelectPic(Corrected);
  119.   Paste;
  120.   Subtract;
  121.   ResetGrayMap;
  122. end;
  123.  
  124.  
  125. macro 'ASCII Dump';
  126. {
  127. Generates an alphanumeric listing of pixels values starting at
  128. the upper left corner of the current selection. 20 rows and 44 columns
  129. can be displayed with the default 552 x 436 window. The size of the window
  130. used to display the pixel values is determined by New Width and
  131. New Height in the Prefernces dialog box.
  132. }
  133. var
  134.   image,dump,roiLeft,roiTop,roiWidth,roiHeight:integer;
  135.   h,v,value,MaxWidth,MaxHeight,width,height:integer;
  136. begin
  137.   image:=PicNumber;
  138.   GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  139.   if roiWidth=0 then begin
  140.     PutMessage('This macro requires a rectangular selection');
  141.     exit;
  142.   end;
  143.   SetForegroundColor(255);
  144.   SetBackgroundColor(0);
  145.   MakeNewWindow('ASCII Dump');
  146.   dump:=PicNumber;
  147.   GetPicSize(width,height);
  148.   MaxWidth:=width div 24 - 2;
  149.   MaxHeight:=height div 9 - 3;
  150.   if roiWidth>MaxWidth then roiWidth:=MaxWidth;
  151.   if roiHeight>MaxHeight then roiHeight:=MaxHeight;
  152.   SetFont('Monaco');
  153.   SetFontSize(9);
  154.   SetText('No background; Left Justified');
  155.   MoveTo(2,12);
  156.   write('    ');
  157.   for h:=roiLeft to roiLeft+roiWidth-1 do write(h:4);
  158.   writeln;
  159.   writeln;
  160.   for v:=roiTop to roiTop+roiHeight-1 do begin
  161.     write(v:3,' ');
  162.     for h:=roiLeft to roiLeft+roiWidth-1 do begin
  163.       ChoosePic(image);
  164.       value:=GetPixel(h,v);
  165.       ChoosePic(dump);
  166.       write(value:4);
  167.     end;
  168.     writeln;
  169.   end;
  170.   ChoosePic(image);
  171. end;
  172.  
  173.  
  174. macro 'Resize All';
  175. {
  176. Resizes and/or rotates all currently open widows. For example,
  177. change the  ScaleAndRotate command below to
  178. ScaleAndRotate(2,2,0)  to change the size of all the images
  179. in a movie loop sequence from 128 x 128 to 256 x 256.
  180. }
  181. var
  182.   i:integer;
  183. begin
  184.   SaveState;
  185.   SetScaling('Bilinear; Create New Window');
  186.   for i:=1 to nPics do begin
  187.     ChoosePic(1);
  188.     ScaleAndRotate(1.9,1.9,0);
  189.     ChoosePic(1);
  190.     Close;
  191.   end;
  192.   for i:=1 to nPics do begin
  193.     ChoosePic(i);
  194.     SetPicName(i);
  195.   end;
  196.   RestoreState;
  197. end;
  198.  
  199.  
  200. macro 'Dispose All';
  201. begin
  202.   DisposeAll;
  203. end;
  204.  
  205. macro 'Average two Images';
  206.   {Generates the arithmetic average of two images.}
  207. begin
  208.   if nPics<>2 then begin
  209.     PutMessage('This macro requires exactly two image windows to be open.');
  210.     Exit;
  211.   End;
  212.   ScaleMath(false);
  213.   MultiplyByConstant(0.5);
  214.   NextWindow;
  215.   MultiplyByConstant(0.5);
  216.   SelectAll;
  217.   Copy;
  218.   NextWindow;
  219.   Paste;
  220.   Add;
  221. end;
  222.  
  223.  
  224. macro 'Make Montage [M]';
  225. {Opens a new window and creates in it a composite image made from all}
  226. {currently open images. All the images must be the same size.}
  227. var
  228.   width,height,w,h,mWidth,mHeight,nWindows,left,top:integer;
  229.   RoiWidth,RoiHeight,RoiWidth,RoiHeight,i,hloc,vloc:integer;
  230.   montage,temp:integer;
  231.   scale:real;
  232.   SameSize:boolean;
  233. begin
  234.   nWindows:=nPics;
  235.   SameSize:=true;
  236.   GetPicSize(width,height);
  237.   for i:=1 to nPics do begin
  238.     SelectPic(i);
  239.     GetPicSize(w,h);
  240.     SameSize:=SameSize and (w=width) and (h=height);
  241.   end;
  242.   if (nWindows<2) or not SameSize then begin
  243.     PutMessage('This macro needs two or more images of the same size in order to create a montage.');
  244.     Exit;
  245.   end;
  246.   SetBackground(0);
  247.   MakeNewWindow('Montage');
  248.   montage:=nWindows+1;
  249.   GetPicSize(mWidth,mHeight);
  250.   SelectPic(1);
  251.   Duplicate('Temp');
  252.   temp:=nWindows+2;
  253.   scale:=GetNumber('Scaling Factor:',0.25);
  254.   hloc:=-(RoiWidth);
  255.   vloc:=0;
  256.   for i:=1 to nWindows do begin
  257.     SelectPic(i);
  258.     SelectAll;
  259.     copy;
  260.     SelectPic(temp);
  261.     paste;
  262.     SelectAll;
  263.     ScaleSelection(scale,scale);
  264.     RestoreRoi;
  265.     if i=1 then begin
  266.       GetRoi(left,top,RoiWidth,RoiHeight);
  267.       hloc:=-RoiWidth;
  268.       vloc:=0;
  269.     end;
  270.     Copy;
  271.     SelectPic(montage);
  272.     hloc:=hloc+RoiWidth;
  273.     if (hloc+RoiWidth)>mWidth then begin
  274.       hloc:=0;
  275.       vloc:=vloc+RoiHeight;
  276.     end;
  277.     MakeRoi(hloc,vloc,RoiWidth,RoiHeight);
  278.     Paste;
  279.   end;
  280.   KillRoi;
  281.   SelectPic(temp);
  282.   Dispose;
  283. end;
  284.  
  285.  
  286. macro 'Make Sine Wave';
  287. var
  288.   left,top,width,height,i:integer;
  289.   ppp,scale:real;
  290. begin
  291.   SaveState;
  292.   MakeNewWindow('Sine Wave');
  293.   SelectAll;
  294.   GetRoi(left,top,Width,Height);
  295.   if width=0 then begin
  296.     PutMessage('This macro requires a rectangular selection.');
  297.     Exit;
  298.   end;
  299.   ppp:=GetNumber('Pixels per period',100);
  300.   Scale:=ppp/6.28;
  301.   MakeRoi(left,top,1,height);
  302.   for i:=1 to width do begin
  303.     SetForeground(sin(i/scale)*127 +128);
  304.     {SetForeground((sin(i/scale)*127 +128)*(i+30)/(width));}
  305.     fill;
  306.     MoveRoi(1,0);
  307.   end;
  308.   KillRoi;
  309.   RestoreState;
  310. end;`
  311.  
  312.  
  313. macro 'Grid';
  314. var
  315.   n,PicWidth,PicHeight,hloc,vloc,size:integer;
  316. begin
  317.   SaveState;
  318.   n:=24;
  319.   GetPicSize(PicWidth,PicHeight);
  320.   if PicWidth=0 then begin
  321.     PutMessage
  322.     ('This macro needs an opened image, preferably in color, to operate on.');
  323.     Exit;
  324.   end;
  325.   size:=round(PicWidth/n);
  326.   repeat
  327.     hloc:=((PicWidth*random) div size)*size;
  328.     vloc:=((PicHeight*random) div size)*size;
  329.     MakeRoi(hloc,vloc,size,size);
  330.     SetForeground(255*random);
  331.     fill;
  332.     {Invert;}
  333.   until Button;
  334.   KillRoi;
  335.   RestoreState;
  336. end;
  337.  
  338.  
  339. macro 'Plot XYZ';
  340. {
  341. Plots X-Y coordinate points with an optional intensity(Z). Values are read from
  342. a 2 or 3 column tab-delimited text file. Data must be scaled as follows:
  343. 0<=X<width; 0<=Y<height; 0<=Z<=255.
  344. }
  345. var
  346.   width,height:integer;
  347. begin
  348.   width:=450;
  349.   height:=500;
  350.   SetNewSize(width,height);
  351.   MakeNewWindow('Plot');
  352.   PlotXYZ;
  353. end;
  354.  
  355.  
  356. macro '(---'; begin end;
  357.  
  358. macro '5x5 [5]';
  359. {
  360. Note: you only see the open file dialog box the first time one of
  361. these macros is called, since Image keeps track of the folder
  362. containing the convolution kernels.
  363. }
  364. begin
  365.   convolve('Hat(5x5)');
  366. end;
  367.  
  368. macro '7x7  [7]'
  369. begin
  370.   convolve('Hat(7x7)');
  371. end;
  372.  
  373. macro '9x9  [9]'
  374. begin
  375.   convolve('Hat(9x9)');
  376. end;
  377.  
  378.  
  379. macro '(---'; begin end;
  380.  
  381. {These macros allow you to easily switch}
  382. {transfer modes while pasting by tapping keys.}
  383. macro 'Copy Mode[F1]'; begin SetOption; DoCopy; end;
  384. macro 'AND Mode[F2]';  begin SetOption; DoAnd; end;
  385. macro 'OR Mode [F3]';  begin SetOption; DoOr; end;
  386.  
  387.